package com.yxt.qmgf.klotski.view;

import com.yxt.qmgf.common.ClientSession;
import com.yxt.qmgf.klotski.ctrl.klotskiController;
import com.yxt.qmgf.userinfo.view.UserInfoTab;
import com.yxt.qmgf.userinfo.vo.UserInfoVO;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.control.Tab;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.net.URL;

public class klotskiTab extends Tab {

    private static volatile klotskiTab instance;

    public UserInfoVO vo = null;

    private klotskiTab(){this("数字华容道");}

    private klotskiTab(String str){
        super(str);
        initView();
    }

    public static klotskiTab getInstance(){
        if (null == instance){
            synchronized (UserInfoTab.class){
                if (null == instance){
                    instance = new klotskiTab();
                }
            }
        }
        return instance;
    }

    private void initView(){
        UserInfoVO vo = (UserInfoVO) ClientSession.getAttribute("user_info");
        URL url = getClass().getResource("/fxml/klotski/klotskiPage.fxml") ;
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(url);
        fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
        try {
            Pane pane = fxmlLoader.load();
            pane.getStylesheets().add(getClass().getResource("/css/yxt.css").toExternalForm());
            setContent(pane);
        } catch (IOException e) {
            e.printStackTrace();
        }
        setClosable(true);
        klotskiController controller =fxmlLoader.getController();
        controller.setOff(vo);
    }

}
